<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <link rel="stylesheet" type="text/css" href="<c:url value="/static/jquery-easyui/themes/metro/easyui.css"/>">
        <link rel="stylesheet" type="text/css"
            href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
        <script type="text/javascript" src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>   
        <script type="text/javascript"
            src="<c:url value="/static/js/common.js"/>"></script>       

<script type="text/javascript">
	$(document).ready(function() {
		$('#tt').tree({
			url : "<c:url value='/role/findMenu.do'/>",
			animate : true,
			checkbox : true,
			loadFilter : function(data) {
				if (data.d) {
					return data.d;
				} else {
					return data;
				}
			}
		});
	});

	//添加信息按钮响应函数
	function addRole() {
		$('#AddRoleForm').form('submit', {
			url : '<c:url value='/role/saveRole.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
                var menuIdAll = getChecked();
				if(menuIdAll == ""){
					$.messager.alert("提示", "请至少选择一个菜单！", 'info');
	                return false;
				}
				document.getElementById("menuIdAll").value = menuIdAll;
				
				if ($('#roleName').val().trim() == "") {
					$.messager.alert("提示", "角色名不能为空！", 'info');
					return false;
				}
			},
			success : function(data) {
				data = eval('(' + data + ')');
				if (data.success) {
					 window.opener.window.tea();
                     $.messager.alert('系统提示', '保存成功', 'info', function(){
                         window.close();
                     });
				} else {
					$.messager.alert("提示", "保存失败！", 'warning');
					window.close();
				}
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});

	}

	function getChecked() {
		var nodes = $('#tt').tree('getChecked');
		var s = '';
		for (var i = 0; i < nodes.length; i++) {
			
			//if (nodes[i].folder !=1){
				if (s != ''){
	                s += ',';
	            }
	            s += nodes[i].id;
			//}
		}
		return s;
	}
</script>
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>

<body>
	<table width="90%" align="center">
		<tr></tr>
		<tr>
			<td>

				<div
					style="width: 90%; height: auto; background: #fafafa; padding: 5px;"
					class="easyui-panel" title="添加角色菜单信息" iconCls="icon-save"
					collapsible="true" minimizable="false" maximizable="false"
					closable="false">

					<form id="AddRoleForm" name="AddRoleForm" method="post">
						<table cellpadding="5">
							<tr>
								<td>角色名:</td>
								<td><input class="easyui-validatebox" type="text"
									id="roleName" name="roleName" required="true"
									validType="length[1,30]" /></td>
							</tr>
							<tr>
								<td>是否有效:</td>
								<td><select class="easyui-combobox" name="isActive">
										<option value="Y">有效</option>
										<option value="N">失效</option>
								</select></td>
							</tr>
							<tr>
                                <td>权限标记:</td>
                                <td><input class="easyui-validatebox" type="text"
                                    id="identity" name="identity" required="true"
                                    validType="length[1,30]" /></td>
                            </tr>

						</table>
						<br> <br>
				<!-------------------------菜单选择----------------------------<br><br>
 			   	<c:forEach var="menu" items="${menuList}" varStatus="status">
                         <input class="menuIds" type="checkbox" name="menuIds" 
                           value="${menu.menuId }">${menu.menuName }</input>
                            <c:if test="${status.count % 5 == 0}">
                              <br><br>
                           </c:if>
                            
                 </c:forEach>
                  <br><br>-->
						<a class="easyui-linkbutton" onclick="addRole()">添加</a>
						<input class="easyui-validatebox" type="text" id="menuIdAll" name="menuIdAll" required="true" hidden="true" />
					</form>

				</div>
			</td>
		</tr>
		<tr>
			<tt>
				<td colspan="2">
					<div
						style="height: auto; width: 90%; background: #fafafa; padding: 5px;"
						class="easyui-panel" title="所有菜单" iconCls="icon-add"
						collapsible="true" minimizable="false" maximizable="false"
						closable="false">
						<table>
							<tr>
								<td>
									<ul id="tt" class="easyui-tree"></ul>
								</td>
							</tr>
						</table>
					</div>
				</td>
			</tt>
		</tr>
	</table>
</body>
</html>